package com.ljm.common.excuption;


import com.ljm.common.constants.SysConstants;
import com.ljm.common.enums.ResultStatus;
import org.springframework.util.StringUtils;

/**
 * 自定义异常
 *
 * @author chenHuaMing
 * @version 2018年5月31日
 * @see BaseException
 * @since
 */
public class BaseException extends RuntimeException {
    /**
     * 线程id
     */
    private static final long serialVersionUID = 1759713087141723190L;
    /**
     * 异常编码
     */
    private String code;
    /**
     * 错误key
     */
    private String errorKey="-1";
    /**
     * 异常描述
     */
    private String errorMsg = "系统出错";
    /**
     * 异常参数
     */
    private Object[] params;
    /**
     * 调用id
     */
    private String traceId;
    /**
     * 结果枚举
     */
    private ResultStatus resultStatus;

    public BaseException(){}
    public BaseException(Exception e) {
        super(e);
    }

    /**
     * 自定义异常（不返回异常信息）
     *
     * @param errorKey 异常key
     * @param errorMsg 异常信息
     */
    public BaseException(String errorKey, String errorMsg) {
        super(errorMsg);
        this.errorKey = errorKey;
        this.errorMsg = errorMsg;
    }

    /**
     * 自定义异常（返回异常信息）
     *
     * @param errorKey
     * @param errorMsg
     * @param cause
     */
    public BaseException(String errorKey, String errorMsg, Throwable cause) {
        super(errorMsg, cause);
        this.errorKey = errorKey;
        this.errorMsg = errorMsg;
    }

    public String getErrorKey() {
        return this.errorKey;
    }

    public String getErrorMsg() {
        return this.errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Object[] getParams() {
        return this.params;
    }

    public void setParams(Object[] params) {
        this.params = params;
    }

    public String getCode() {
        return this.code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getTraceId() {
        return StringUtils.isEmpty(this.traceId)?SysConstants.TRACKID_TL.get():this.traceId;
    }

    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }

    public ResultStatus getResultStatus() {
        return resultStatus;
    }

    public void setResultStatus(ResultStatus resultStatus) {
        this.resultStatus = resultStatus;
    }
}
